<template>
  <div class="cbody">
    <div>
      <el-container>
        <el-header height="20px">
          <div style="display: flex">
            <el-select v-model="query.type">
              <el-option
                v-for="item in ['生产','收料']"
                :key="item"
                :label="item"
                :value="item"
              />
            </el-select>
            <el-input v-model="query.socode" class="search-inp" placeholder="需求单号" />
            <el-input v-model="query.mocode" class="search-inp" placeholder="生产单号" />
            <el-input v-model="query.cbarcode" class="search-inp" placeholder="条码" />
            <el-button class="hand-btn" type="primary" icon="el-icon-search" @click="handleSearch">查询</el-button>
          </div>
        </el-header>
        <el-main>
          <el-table
            v-loading="loading"
            :data="page.content"
            max-height="560"
            height="560"
            :cell-style="{'padding':'2px','font-size':'12px'}"
            :header-cell-style="{'padding':'0px','font-weight':'800'}"
            tooltip-effect="dark"
            border
            style="width: 100%;"
          >
            <el-table-column
              type="index"
              label="项次"
              width="50"
            />
            <el-table-column
              prop="SoCode"
              label="需求跟踪号"
            />
            <el-table-column
              prop="cBDefine13"
              width="70px"
              label="状态"
            >
              <template slot-scope="scope">
                {{ scope.row.qcyqty?(scope.row.Qty - scope.row.qcyqty > 0 ? '检验中':'已检验') :'待质检' }}
              </template>
            </el-table-column>
            <el-table-column
              prop="MoCode"
              label="生产单号"
            />
            <el-table-column
              prop="MoDId"
              label="明细单号"
            />
            <el-table-column
              prop="cInvName"
              label="产品名称"
            />
            <el-table-column
              prop="Qty"
              label="数量"
            />
            <el-table-column label="操作" width="120" align="center">
              <template slot-scope="scope">
                <el-button
                  type="text"
                  icon="el-icon-edit"
                  style="color: #52b0fd"
                  @click="findAllByModid(scope.row)"
                >质检</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-main>
        <el-footer height="50px">
          <div class="pagination">
            <el-pagination
              background
              layout="total,sizes, prev, pager, next"
              :page-sizes="[10,20, 30, 40, 50]"
              :current-page="query.pageIndex"
              :page-size="query.pageSize"
              :total="page.totalElements"
              @size-change="handleSizeChange"
              @current-change="handlePageChange"
            />
          </div>
        </el-footer>
      </el-container>
    </div>
    <el-dialog style="padding: 10px" :visible.sync="selable" width="80%" :body-style="{padding:'50px 50px'}" :close-on-click-modal="false">
      <div style="display: flex;justify-content: space-between">
        <div><el-button @click="selBarcodes">选择</el-button></div>
        <div>{{ query.type }}</div>
      </div>
      <el-container>
        <el-table
          v-loading="loading"
          :data="barcodeDatas"
          max-height="560"
          height="560"
          :cell-style="{'padding':'2px','font-size':'12px'}"
          :header-cell-style="{'padding':'0px','font-weight':'800'}"
          tooltip-effect="dark"
          border
          style="width: 100%;"
        >
          <el-table-column
            prop="selection"
            width="50px"
          >
            <template slot-scope="scope">
              <div><el-checkbox v-show="!scope.row.qctime&&!scope.row.cstatus && ((query.type == '生产' && !scope.row.slddate)||(scope.row.slddate && query.type == '接收'))" v-model="scope.row.checked" /></div>
            </template>
          </el-table-column>
          <el-table-column
            prop="cbarcode"
            width="120px"
            label="条码"
          />
          <el-table-column
            prop="cbarcodeno"
            width="70px"
            label="板号"
          />
          <el-table-column
            prop="qty"
            width="70px"
            label="数量"
          />
          <el-table-column
            prop="dissemblename"
            label="描述"
          />
          <el-table-column
            width="120px"
            label="状态"
          >
            <template slot-scope="scope">
              {{ scope.row.slddate ? '已收':'待收' }}-- {{ scope.row.qctime ? '已检': scope.row.stepvalue =='质检' ? '返工' :'待检' }}
            </template>
          </el-table-column>
          <el-table-column
            width="100px"
            label="作废"
          >
            <template slot-scope="scope">
              {{ scope.row.cstatus ? '作废':'' }}
            </template>
          </el-table-column>
          <el-table-column
            width="100px"
          >
            <template slot-scope="scope">
              <el-button v-show="scope.row.qctime|| scope.row.stepvalue =='质检'" size="mini" type="default" @click="showBill(scope.row.cbarcode)">查看</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-container>
    </el-dialog>
    <!-------------------------------表格 ----------------------down ------------------->
    <el-dialog style="padding: 10px" :visible.sync="editVisible" width="80%" :body-style="{padding:'50px 50px'}" :close-on-click-modal="false">
      <div class="content">
        <div style="display: flex;justify-content: space-between;margin-right: 10px">
          <div>
            质检场景：{{ query.type }}
          </div>
          <div>
            <div scroll-y="true" style="overflow:auto;height: 20px">
              <div v-for="(item, index) in barcodes" :key="index">
                {{ item.cbarcode }}-{{ item.cbarcodeno }}
              </div>
            </div>
          </div>
          <div style="display: flex;justify-content: space-between;margin-right: 10px">
            <div>
              <label><input v-model="form.billtype" type="radio" value="生产质检" name="billtype">生产质检</label>
            </div>
            <div>
              <label><input v-model="form.billtype" type="radio" value="最终质检" name="billtype">最终质检</label>
            </div>
            <div>
              <label><input v-model="form.billtype" type="radio" value="半成品" name="billtype">半成品</label>
            </div>
            <div>
              <label><input v-model="form.billtype" type="radio" value="成品" name="billtype">成品</label>
            </div>
          </div>
          <div>
            抽样标准:GB2828.1-2012
          </div>
        </div>
        <!-------------------------------表格 ----------------------down ------------------->
        <table class="table">
          <thead>
            <tr>
              <td class="topth">
                拉别
              </td>
              <td> <el-input v-model="form.define33" class="topth" /></td>
              <td class="topth">
                生产日期/品牌
              </td>
              <td> {{ form.ddate }}/{{ form.free2 }}</td>
              <td class="topth">
                需求跟踪号
              </td>
              <td> {{ form.csocode }}</td>
            </tr>
            <tr>
              <td class="topth">
                产品型号
              </td>
              <td> {{ form.csoinvname }}</td>
              <td class="topth">
                本次数/总数量
              </td>
              <td><el-input v-model="form.qcyqty" type="number" class="topth" @change="changeLevel"/> /   {{ form.qty }} </td>
              <td class="topth">
                抽样数
              </td>
              <td> <input v-model="form.checkqty" type="number" class="topth" @change="changeLevel"> </td>
            </tr>
          </thead>
        </table>
        <!-------------------------------主信息 ----------------------up ------------------->
        <!-------------------------------下拉选择 ----------------------up ------------------->
        <table class="table">
          <thead>
            <tr>
              <th width="50px" rowspan="3">
                产品要求核对
              </th>
              <th class="mincell" rowspan="2">
                过充
              </th>
              <th class="mincell" rowspan="2">
                过放
              </th>
              <th class="mincell" rowspan="2">
                DC
              </th>
              <th class="mincell" rowspan="2">
                AC
              </th>
              <th class="mincell" rowspan="2">
                S-AC
              </th>
              <th class="mincell" rowspan="2">
                电压
              </th>
              <th class="mincell" rowspan="2">
                电源线
              </th>
              <th class="mincell" rowspan="2">
                充电
              </th>
              <th class="mincell" rowspan="2">
                拉线开关
              </th>
              <th class="mincell" rowspan="2">
                检测开关
              </th>
              <th class="mincell" rowspan="2">
                反光纸
              </th>
              <th class="mincell" rowspan="2">
                防水
              </th>
              <th class="mincell" rowspan="2">
                外置天线
              </th>

              <th class="mincell" colspan="2">
                LED
              </th>
              <th class="mincell" colspan="3">
                电筒功能
              </th>
              <th class="mincell" colspan="2">
                射灯
              </th>
              <th class="mincell" colspan="2">
                电池
              </th>
              <th class="mincell" rowspan="2">
                使用时间
              </th>
              <th class="mincell" colspan="2">
                索件
              </th>
              <th class="mincell" rowspan="2">
                整灯
              </th>
              <th class="mincell" rowspan="2">
                散件
              </th>
            </tr>
            <tr>
              <th class="mincell">
                串
              </th>
              <th class="mincell">
                并
              </th>
              <th class="mincell">
                单
              </th>
              <th class="mincell">
                双
              </th>
              <th class="mincell">
                三
              </th>
              <th class="mincell">
                LED
              </th>
              <th class="mincell">
                灯珠
              </th>
              <th class="mincell">
                片数
              </th>
              <th class="mincell">
                重量
              </th>
              <th class="mincell">
                用料
              </th>
              <th class="mincell">
                颜色配置
              </th>
            </tr>
            <tr>
              <td>
                <select v-model="form.guochong" class="cselect">
                  <option v-for="(item,index) in options" :key="index" :value="item">{{ item }}</option>
                </select>
              </td>
              <td>
                <select v-model="form.guofang" class="cselect">
                  <option v-for="(item,index) in options" :key="index" :value="item">{{ item }}</option>
                </select>
              </td>
              <td>
                <select v-model="form.dc" class="cselect">
                  <option v-for="(item,index) in options" :key="index" :value="item">{{ item }}</option>
                </select>
              </td>
              <td>
                <select v-model="form.ac" class="cselect">
                  <option v-for="(item,index) in options" :key="index" :value="item">{{ item }}</option>
                </select>
              </td>
              <td>
                <select v-model="form.sac" class="cselect">
                  <option v-for="(item,index) in options" :key="index" :value="item">{{ item }}</option>
                </select>
              </td>
              <td>
                <select v-model="form.dianya" class="cselect">
                  <option v-for="(item,index) in options" :key="index" :value="item">{{ item }}</option>
                </select>
              </td>
              <td>
                <select v-model="form.dianyuanxian" class="cselect">
                  <option v-for="(item,index) in options" :key="index" :value="item">{{ item }}</option>
                </select>
              </td>
              <td>
                <select v-model="form.chondian" class="cselect">
                  <option v-for="(item,index) in options" :key="index" :value="item">{{ item }}</option>
                </select>
              </td>
              <td>
                <select v-model="form.laxiankaiguan" class="cselect">
                  <option v-for="(item,index) in options" :key="index" :value="item">{{ item }}</option>
                </select>
              </td>
              <td>
                <select v-model="form.jiancekaiguan" class="cselect">
                  <option v-for="(item,index) in options" :key="index" :value="item">{{ item }}</option>
                </select>
              </td>
              <td>
                <select v-model="form.fanguangzhi" class="cselect">
                  <option v-for="(item,index) in options" :key="index" :value="item">{{ item }}</option>
                </select>
              </td>
              <td>
                <select v-model="form.fangshui" class="cselect">
                  <option v-for="(item,index) in options" :key="index" :value="item">{{ item }}</option>
                </select>
              </td>
              <td>
                <select v-model="form.waizhitianxian" class="cselect">
                  <option v-for="(item,index) in options" :key="index" :value="item">{{ item }}</option>
                </select>
              </td>
              <td>
                <select v-model="form.ledchuan" class="cselect">
                  <option v-for="(item,index) in options" :key="index" :value="item">{{ item }}</option>
                </select>
              </td>
              <td>
                <select v-model="form.ledbing" class="cselect">
                  <option v-for="(item,index) in options" :key="index" :value="item">{{ item }}</option>
                </select>
              </td>
              <td>
                <select v-model="form.diantongdan" class="cselect">
                  <option v-for="(item,index) in options" :key="index" :value="item">{{ item }}</option>
                </select>
              </td>
              <td>
                <select v-model="form.diantongshuang" class="cselect">
                  <option v-for="(item,index) in options" :key="index" :value="item">{{ item }}</option>
                </select>
              </td>
              <td>
                <select v-model="form.diantongsan" class="cselect">
                  <option v-for="(item,index) in options" :key="index" :value="item">{{ item }}</option>
                </select>
              </td>
              <td>
                <select v-model="form.shedengled" class="cselect">
                  <option v-for="(item,index) in options" :key="index" :value="item">{{ item }}</option>
                </select>
              </td>
              <td>
                <select v-model="form.shedengdanzhu" class="cselect">
                  <option v-for="(item,index) in options" :key="index" :value="item">{{ item }}</option>
                </select>
              </td>
              <td>
                <select v-model="form.dianchipainshu" class="cselect">
                  <option v-for="(item,index) in options" :key="index" :value="item">{{ item }}</option>
                </select>
              </td>
              <td>
                <select v-model="form.dianchizhongliang" class="cselect">
                  <option v-for="(item,index) in options" :key="index" :value="item">{{ item }}</option>
                </select>
              </td>
              <td>
                <select v-model="form.shiyongshijian" class="cselect">
                  <option v-for="(item,index) in options" :key="index" :value="item">{{ item }}</option>
                </select>
              </td>
              <td>
                <select v-model="form.suojianyongliao" class="cselect">
                  <option v-for="(item,index) in options" :key="index" :value="item">{{ item }}</option>
                </select>
              </td>
              <td>
                <select v-model="form.suojianyanse" class="cselect">
                  <option v-for="(item,index) in options" :key="index" :value="item">{{ item }}</option>
                </select>
              </td>
              <td>
                <select v-model="form.zhengdeng" class="cselect">
                  <option v-for="(item,index) in options" :key="index" :value="item">{{ item }}</option>
                </select>
              </td>
              <td>
                <select v-model="form.sandjian" class="cselect">
                  <option v-for="(item,index) in options" :key="index" :value="item">{{ item }}</option>
                </select>
              </td>
            </tr>
            <tr>
              <th width="50px" rowspan="3">
                包装及丝印核对
              </th>
              <th class="mincell" rowspan="2">
                客户型号
              </th>
              <th class="mincell" rowspan="2">
                品牌
              </th>
              <th class="mincell" rowspan="2">
                光管
              </th>
              <th class="mincell" rowspan="2">
                电池
              </th>
              <th class="mincell" rowspan="2">
                塑件
              </th>
              <th class="mincell" rowspan="2">
                PCS/CN
              </th>
              <th class="mincell" rowspan="2">
                内包装
              </th>
              <th class="mincell" rowspan="2">
                彩盒
              </th>
              <th class="mincell" rowspan="2">
                说明书保修卡等
              </th>
              <th class="mincell" rowspan="2">
                胶袋⌒ 文字 ︶
              </th>
              <th class="mincell" rowspan="2">
                正唛
              </th>
              <th class="mincell" rowspan="2">
                侧唛
              </th>

              <th class="mincell" colspan="8">
                标贴
              </th>
              <th class="mincell" colspan="7" rowspan="2">
                卡通（颜色/字体/文字/封箱胶）
              </th>
            </tr>
            <tr>
              <th class="mincell">
                产地标
              </th>
              <th class="mincell">
                QC标
              </th>
              <th class="mincell">
                电压标
              </th>
              <th class="mincell">
                封口标
              </th>
              <th class="mincell">
                条形标
              </th>
              <th class="mincell">
                认证标
              </th>
              <th class="mincell" colspan="2">
                其它标
              </th>
            </tr>
            <tr>
              <td>
                <select v-model="form.kehuxinghao" class="cselect">
                  <option v-for="(item,index) in options" :key="index" :value="item">{{ item }}</option>
                </select>
              </td>
              <td>
                <select v-model="form.pingpai" class="cselect">
                  <option v-for="(item,index) in options" :key="index" :value="item">{{ item }}</option>
                </select>
              </td>
              <td>
                <select v-model="form.guangguan" class="cselect">
                  <option v-for="(item,index) in options" :key="index" :value="item">{{ item }}</option>
                </select>
              </td>
              <td>
                <select v-model="form.dianchi" class="cselect">
                  <option v-for="(item,index) in options" :key="index" :value="item">{{ item }}</option>
                </select>
              </td>
              <td>
                <select v-model="form.suojian" class="cselect">
                  <option v-for="(item,index) in options" :key="index" :value="item">{{ item }}</option>
                </select>
              </td>
              <td>
                <select v-model="form.pcs" class="cselect">
                  <option v-for="(item,index) in options" :key="index" :value="item">{{ item }}</option>
                </select>
              </td>
              <td>
                <select v-model="form.neibaozhuang" class="cselect">
                  <option v-for="(item,index) in options" :key="index" :value="item">{{ item }}</option>
                </select>
              </td>
              <td>
                <select v-model="form.caihe" class="cselect">
                  <option v-for="(item,index) in options" :key="index" :value="item">{{ item }}</option>
                </select>
              </td>
              <td>
                <select v-model="form.shuomingshu" class="cselect">
                  <option v-for="(item,index) in options" :key="index" :value="item">{{ item }}</option>
                </select>
              </td>
              <td>
                <select v-model="form.jiaodai" class="cselect">
                  <option v-for="(item,index) in options" :key="index" :value="item">{{ item }}</option>
                </select>
              </td>
              <td>
                <select v-model="form.zhengsuo" class="cselect">
                  <option v-for="(item,index) in options" :key="index" :value="item">{{ item }}</option>
                </select>
              </td>
              <td>
                <select v-model="form.cesuo" class="cselect">
                  <option v-for="(item,index) in options" :key="index" :value="item">{{ item }}</option>
                </select>
              </td>
              <td>
                <select v-model="form.chandibiao" class="cselect">
                  <option v-for="(item,index) in options" :key="index" :value="item">{{ item }}</option>
                </select>
              </td>
              <td>
                <select v-model="form.qcbiao" class="cselect">
                  <option v-for="(item,index) in options" :key="index" :value="item">{{ item }}</option>
                </select>
              </td>
              <td>
                <select v-model="form.dianyabiao" class="cselect">
                  <option v-for="(item,index) in options" :key="index" :value="item">{{ item }}</option>
                </select>
              </td>
              <td>
                <select v-model="form.fengkoubiao" class="cselect">
                  <option v-for="(item,index) in options" :key="index" :value="item">{{ item }}</option>
                </select>
              </td>
              <td>
                <select v-model="form.tiaoxingbiao" class="cselect">
                  <option v-for="(item,index) in options" :key="index" :value="item">{{ item }}</option>
                </select>
              </td>
              <td>
                <select v-model="form.renzhengbiao" class="cselect">
                  <option v-for="(item,index) in options" :key="index" :value="item">{{ item }}</option>
                </select>
              </td>
              <td colspan="2">
                <select v-model="form.qitabiao" class="cselect">
                  <option v-for="(item,index) in options" :key="index" :value="item">{{ item }}</option>
                </select>
              </td>
              <td colspan="7">
                <select v-model="form.katong" class="cselect">
                  <option v-for="(item,index) in options" :key="index" :value="item">{{ item }}</option>
                </select>
              </td>
            </tr>
          </thead>
        </table>
        <!-------------------------------下拉选择 ----------------------up ------------------->
        <!-------------------------------大表格 ----------------------down ------------------->
        <table class="table">
          <tr>
            <th>
              检测项目
            </th>
            <th>
              检测内容
            </th>
            <th width="20px">
              轻缺陷数量
            </th>
            <th width="20px">
              重缺陷数量
            </th>
            <th width="20px">
              致命缺陷数量
            </th>
          </tr>
          <tr>
            <td width="100px" rowspan="3">
              外观
            </td>
            <td>
              <textarea v-model="form.baozhuang" rows="3" cols="60" placeholder="包装：" />
            </td>
            <td>
              <input v-model="form.wgq1" type="number" min="0" class="cnumber">
            </td>
            <td>
              <input v-model="form.wgz1" type="number" min="0" class="cnumber">
            </td>
            <td>
              <input v-model="form.wgzm1" type="number" min="0" class="cnumber">
            </td>
          </tr>
          <tr>
            <td>
              <textarea v-model="form.waiguan" rows="3" cols="60" placeholder="外观：" />
            </td>
            <td>
              <input v-model="form.wgq2" type="number" min="0" class="cnumber">
            </td>
            <td>
              <input v-model="form.wgz2" type="number" min="0" class="cnumber">
            </td>
            <td>
              <input v-model="form.wgzm2" type="number" min="0" class="cnumber">
            </td>
          </tr>
          <tr>
            <td>
              <textarea v-model="form.jiegouzuzhuang" rows="3" cols="60" placeholder="结构组装：" />
            </td>
            <td>
              <input v-model="form.wgq3" type="number" min="0" class="cnumber">
            </td>
            <td>
              <input v-model="form.wgz3" type="number" min="0" class="cnumber">
            </td>
            <td>
              <input v-model="form.wgzm3" type="number" min="0" class="cnumber">
            </td>
          </tr>
          <tr>
            <td width="100px">
              性能
            </td>
            <td>
              <table class="intable">
                <tr>
                  <td>充电方式:</td><td><input v-model="form.chongdianfangshi"></td>
                </tr>
                <tr>
                  <td>电池批号:</td><td><input v-model="form.dianchipihao"></td>
                </tr>
                <tr>
                  <td>充电电流标准:</td><td><input v-model="form.chongdiandianliubiaozhun"></td>
                  <td>测试值:</td><td><input v-model="form.ceshi1"></td>
                </tr>
                <tr>
                  <td>漏电流标准:</td><td><input v-model="form.loudianliubiaozhun"></td>
                  <td>测试值:</td><td><input v-model="form.ceshi2"></td>
                </tr>
                <tr>
                  <td>工作电流标准:</td><td><input v-model="form.gongzuodianliubiaozhun"></td>
                  <td>测试值:</td><td><input v-model="form.ceshi3"></td>
                </tr>
                <tr>
                  <td /><td><input v-model="form.kongbai1"></td>
                  <td>测试值:</td><td><input v-model="form.ceshi4"></td>
                </tr>
                <tr>
                  <td /><td><input v-model="form.kongbai2"></td>
                  <td>测试值:</td><td><input v-model="form.ceshi5"></td>
                </tr>
                <tr>
                  <td /><td><input v-model="form.kongbai3"></td>
                  <td>测试值:</td><td><input v-model="form.ceshi6"></td>
                </tr>
                <tr>
                  <td /><td><input v-model="form.kongbai4"></td>
                  <td>测试值:</td><td><input v-model="form.ceshi7"></td>
                </tr>
              </table>
              <textarea v-model="form.gongnengceshi" rows="6" cols="60" placeholder="性能测试：" />
            </td>
            <td>
              <input v-model="form.wgq4" type="number" min="0" class="cnumber">
            </td>
            <td>
              <input v-model="form.wgz4" type="number" min="0" class="cnumber">
            </td>
            <td>
              <input v-model="form.wgzm4" type="number" min="0" class="cnumber">
            </td>
          </tr>
        </table>
        <!-------------------------------div ----------------------down ------------------->
        <div class="condiv">
          <div class="ditem">
            <div>
              <div class="lditem">
                落地测试：<select v-model="form.downtest" style="width: 200px">
                  <option v-for="(item,index) in downtests" :key="index" :value="item">{{ item }}</option>
                </select>
              </div>
              <div class="lditem" style="display: flex">
                <div>高压测试</div>
                <div class="wditem">
                  <div><label><input v-model="form.gaoya" :disabled="form.downtest == '/'" name="gaoya" value="1" class="gaoya" type="radio"> 1500V  5mA  3秒</label></div>
                  <div><label><input v-model="form.gaoya" :disabled="form.downtest == '/'" name="gaoya" value="2" class="gaoya" type="radio"> 3000V  5mA  3秒  </label></div>
                  <div><label><input v-model="form.gaoya" :disabled="form.downtest == '/'" name="gaoya" value="3" class="gaoya" type="radio">
                    <input v-model="form.gaoyai" :disabled="form.downtest == '/'" type="number" style="width: 60px"> V 5mA  3秒 </label></div>
                </div>
              </div>
              <div>
                <div class="lditem">
                  检测水平：<select v-model="form.level" style="width: 200px" @change="changeLevel">
                    <option v-for="(item,index) in levels" :key="index" :value="item">{{ item }}</option>
                  </select>
                </div>
                <div class="lditem">
                  结果：
                  <span class="mditem">A<input v-model="form.jieguoa" class="mditem minp" type="number">台</span>
                  <span>B<input v-model="form.jieguob" class="mditem minp" type="number">台</span>
                  <span class="mditem">C<input v-model="form.jieguoc" class="mditem minp" type="number">台</span>
                </div>
              </div>
            </div>
            <div>
              <div class="lditem">
                AQL值：
                <span>
                  A：<select v-model="form.aqla" style="width: 100px" @change="changeAqla">
                    <option v-for="(item,index) in grades" :key="index" :value="item">{{ item }}</option>
                  </select>
                </span>
                <span>
                  B：<select v-model="form.aqlb" style="width: 100px" @change="changeAqlb">
                    <option v-for="(item,index) in grades" :key="index" :value="item">{{ item }}</option>
                  </select>
                </span>
                <span>
                  C：<select v-model="form.aqlc" style="width: 100px" @change="changeAqlc">
                    <option v-for="(item,index) in grades" :key="index" :value="item">{{ item }}</option>
                  </select>
                </span>
              </div>
              <div class="lditem" style="display: flex">
                AC/RE值：
                <div class="uspan">
                  A:<u>__{{ form.aca }}__/___{{ form.rea }}__</u>
                </div>
                <div class="uspan">
                  B:<u>__{{ form.acb }}__/__{{ form.reb }}__</u>
                </div>
                <div class="uspan">
                  C:<u>__{{ form.acc }}__/__{{ form.rec }}__</u>
                </div>
              </div>
              <div style="display: flex">
                <div>
                  判定：
                </div>
                <div>
                  <div>
                    <label class="">合格：<input v-model="form.panding" name="panding" value="合格" type="radio" class="mditem"></label>
                    <label>不合格：<input v-model="form.panding" name="panding" value="不合格" type="radio" class="mditem"></label>
                  </div>
                  <!--<div>-->
                  <!--<label>全检：<input v-model="form.panding" name="panding" value="全检" type="radio" class="mditem"></label>-->
                  <!--<label>反工：<input v-model="form.panding" name="panding" value="反工" type="radio" class="mditem"></label>-->
                  <!--</div>-->
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="condiv">
          <el-upload
            :action="fileUploadURL"
            list-type="picture-card"
            :on-success="handleUploadSuccess"
            :on-preview="handlePictureCardPreview"
            :on-exceed="handleExceed"
            :limit="6"
            :file-list="filList"
            :on-remove="handleRemove"
          >
            <i class="el-icon-plus" />
          </el-upload>
          <el-dialog :visible.sync="dialogVisible">
            <img width="100%" :src="dialogImageUrl" alt="">
          </el-dialog>
        </div>
        <!-- <div class="condiv">
          <textarea v-model="form.remark" rows="6" cols="60" placeholder="审核备注：" />
          <el-radio-group v-model="form.measurement">
            <el-radio label="合格">合格</el-radio>
            <el-radio label="特采">特采</el-radio>
            <el-radio label="全检">全检</el-radio>
            <el-radio label="返工">返工</el-radio>
          </el-radio-group>
        </div>-->
      </div>

      <div style="text-align: right;margin-right: 20px">
        <el-button size="normal" @click="editVisible = false">取消</el-button>
        <el-button type="success" size="normal" @click="saveEdit">保存</el-button>
      </div>
    </el-dialog>
    <!-------------------------------表格 ----------------------top ------------------->
  </div>
</template>
<script>import { u8query } from '@/api/qcproduce'
import { finish } from '@/api/qcproduce'
import { queryByPage as selectMomorder } from '@/api/selectMomorder'
import { queryByPage as selectMomorder2 } from '@/api/selectMomorder2'
import { findAllByModid } from '@/api/ppbarcode'
import { findByBarcode } from '@/api/ppbarcode'
import { save } from '@/api/rpproduce'
import { findRpProduceBySubBarcode } from '@/api/rpproduce'
import { get } from '@/api/qmilcode'
import { findDemoByLevelAndQty } from '@/api/qmilcode'
import { get as getBillByid } from '@/api/u8QcProduce'
import { findRpProduceByBarcode } from '@/api/rpproduce'
import { getNext } from '@/api/rpproduce'
import { getLast } from '@/api/rpproduce'
import { get as getRpproduce } from '@/api/rpproduce'
export default {
  name: 'Qm105e',
  data() {
    return {
      downtests: ['/', '合格', '不合格', '不适用'],
      dialogVisible: false,
      dialogImageUrl: '',
      editVisible: false,
      selable: false,
      canshenhe: false,
      filList: [],
      fileURL: process.env.VUE_APP_BASE_API,
      fileUploadURL: process.env.VUE_APP_BASE_API + '/file/upload',
      form: {},
      query: {
        type: '生产',
        socode: '',
        mocode: ''
      },
      barcodes: [],
      page: [],
      barcodeDatas: [],
      loading: false,
      grades: [0, 0.25, 0.4, 0.65, 1.0, 1.5, 2.5, 4.0, 6.5, 10, 15, 25],
      levels: ['S-1', 'S-2', 'S-3', 'S-4', 'I', 'II', 'III'],
      options: ['/', '√', '×'],
      datas: []
    }
  },
  created() {
    if (this.$route.query.id) {
      this.getInCome(this.$route.query.id)
    }
    this.handleSearch()
  },
  methods: {
    getInCome(id) {
      this.loading = true
      getRpproduce(id).then(res => {
        this.editVisible = true
        this.loading = false
        this.form = res.data.data
        this.filList = []
        for (const image of this.form.images) {
          this.filList.push({ url: this.fileURL + image.imgUrl })
        }
      })
    },
    getBills() {
      if (this.query.cbarcode) {
        this.findByBarcode(this.query.cbarcode)
      } else {
        if (this.query.type === '生产') {
          this.getBillByselectMomorder()
        } else {
          this.getBillByselectMomorder2()
        }
      }
    },
    findByBarcode(cbarcode) {
      findByBarcode(cbarcode).then(res => {
        const item = res.data.page
        if (item) {
          this.query.mocode = item.MoCode
          this.query.socode = item.SoCode
        }
        if (this.query.type === '生产') {
          this.getBillByselectMomorder()
        } else {
          this.getBillByselectMomorder2()
        }
      })
    },
    getBillByselectMomorder() {
      selectMomorder(this.query).then(res => {
        this.page = res.data.page
      })
    },
    getBillByselectMomorder2() {
      selectMomorder2(this.query).then(res => {
        this.page = res.data.page
      })
    },
    findAllByModid(row) {
      findAllByModid(row.MoDId).then(res => {
        this.form.modid = row.MoDId
        this.barcodeDatas = res.data.page
        this.selable = true
      })
    },
    selselections(selection) {
      console.log(selection)
    },
    showBill(cbarcode) {
      findRpProduceBySubBarcode(cbarcode).then(res => {
        console.log(res.data.data)
        this.form = res.data.data
        this.editVisible = true
      })
    },
    getBill(moid) {
      getBillByid(moid).then(res => {
        const row = res.data.data
        console.log(row)
        if (!row) {
          this.$message.warning('单据已关闭!')
          return
        }
        this.form.cinvcode = row.InvCode
        this.form.mdepcode = row.MDepCode
        this.form.mocode = row.MoCode
        this.form.moid = row.MoId
        this.form.modid = row.MoDId
        this.form.qty = row.Qty
        this.form.qcyqty = 0
        for (const bar of this.barcodes) {
          this.form.qcyqty += bar.qty
        }
        this.form.ccomunitname = row.cComUnitName
        this.form.cdepname = row.cDepName
        this.form.define33 = row.Define33
        this.form.cinvname = row.cInvName
        this.form.cinvstd = row.cInvStd
        this.form.ddate = row.dDate
        this.form.free2 = row.Free2
        this.form.socode = row.socode
        this.form.isosid = row.iSOsID
        this.form.csoinvname = row.csoinvname
        this.form.csocode = row.cSOCode
        this.form.soseq = row.SoSeq
        this.form.sortseq = row.SortSeq

        if (!this.form.id) {
          this.diffValue(this.form)
          this.changeLevel()
        }
        this.form.measurement = undefined
        this.$forceUpdate()
      })
    },
    diffValue(data) {
      data.guochong = '√'
      data.guofang = '√'
      data.dc = '√'
      data.ac = '√'
      data.sac = '√'
      data.dianya = '√'
      data.dianyuanxian = '√'
      data.chondian = '√'
      data.laxiankaiguan = '√'
      data.jiancekaiguan = '√'
      data.fanguangzhi = '√'
      data.fangshui = '√'
      data.waizhitianxian = '√'
      data.ledchuan = '√'
      data.ledbing = '√'
      data.diantongdan = '√'
      data.diantongshuang = '√'
      data.diantongsan = '√'
      data.shedengled = '√'
      data.shedengdanzhu = '√'
      data.dianchipainshu = '√'
      data.dianchizhongliang = '√'
      data.shiyongshijian = '√'
      data.suojianyongliao = '√'
      data.suojianyanse = '√'
      data.zhengdeng = '√'
      data.pcs = '√'
      data.sandjian = '√'
      data.kehuxinghao = '√'
      data.pingpai = '√'
      data.guangguan = '√'
      data.dianchi = '√'
      data.suojian = '√'
      data.neibaozhuang = '√'
      data.caihe = '√'
      data.shuomingshu = '√'
      data.jiaodai = '√'
      data.zhengsuo = '√'
      data.cesuo = '√'
      data.chandibiao = '√'
      data.qcbiao = '√'
      data.dianyabiao = '√'
      data.fengkoubiao = '√'
      data.tiaoxingbiao = '√'
      data.renzhengbiao = '√'
      data.qitabiao = '√'
      data.katong = '√'

      data.wgq1 = 0
      data.wgz1 = 0
      data.wgzm1 = 0

      data.wgq2 = 0
      data.wgz2 = 0
      data.wgzm2 = 0

      data.wgq3 = 0
      data.wgz3 = 0
      data.wgzm3 = 0

      data.wgq4 = 0
      data.wgz4 = 0
      data.wgzm4 = 0

      data.level = 'II'
      data.jieguoa = 0
      data.jieguob = 0
      data.jieguoc = 0

      data.downtest = '/'
    },
    getRpproduceByBarcode(ppbarcode) {
      findRpProduceByBarcode(ppbarcode).then(res => {
        const row = res.data.data
        if (row) {
          row.id = null
          row.measurement = null
          this.form = row
          this.form.qcyqty = 0
          for (const bar of this.barcodes) {
            this.form.qcyqty += bar.qty
          }
          for (const image of this.form.images) {
            this.filList.push({ 'url': this.fileUploadUrl + image.imgUrl, 'imgUrl': image.imgUrl })
          }
          //this.changeQcyqty(1)
        } else {
          this.getBill(this.form.modid)
        }
      })
    },
    saveEdit() {
      const images = []
      for (const image of this.filList) {
        images.push({ imgUrl: image.imgUrl })
      }
      this.form.images = images
      this.form.qctype = this.query.type
      this.form.barcodes = this.barcodes
      save(this.form).then(res => {
        if (res.code === 200) {
          this.$message.success('保存成功')
          this.form = res.data.rpproduce
        } else {
          this.$message.error(res.message)
        }
      })
    },
    selBarcodes() {
      const data = []
      let totalqty = 0
      for (const item of this.barcodeDatas) {
        if (item.checked) {
          totalqty += item.qty
          data.push({ cbarcode: item.cbarcode, cbarcodeno: item.cbarcodeno, qty: item.qty })
        }
      }
      if (data.length > 0) {
        this.barcodes = data
        this.form.qcyqty = totalqty
        this.editVisible = true
        this.getRpproduceByBarcode(this.barcodes[0].cbarcode)
      }
    },
    // 触发搜索按钮
    handleSearch() {
      this.$set(this.query, 'pageIndex', 1)
      this.getBills()
    },
    handlePageChange(val) {
      this.$set(this.query, 'pageIndex', val)
      this.getBills()
    },
    // 分页大小改变
    handleSizeChange(val) {
      this.$set(this.query, 'pageSize', val)
      this.getBills()
    },
    getData() {
      u8query(this.query).then(res => {
        this.page = res.data.page
      })
    },
    selTable(row) {
      this.editVisible = false
      this.form.cinvcode = row.cInvCode
      this.form.mdepcode = row.MDepCode
      this.form.mocode = row.MoCode
      this.form.moid = row.MoId
      this.form.modid = row.MoDId
      this.form.qty = row.Qty
      if (row.qcyqty) {
        this.form.qcyqty = row.Qty - row.qcyqty
      } else {
        this.form.qcyqty = row.Qty
      }
      this.form.ccomunitname = row.cComUnitName
      this.form.cdepname = row.cDepName
      this.form.define33 = row.Define33
      this.form.free2 = row.Free2
      this.form.cinvname = row.cInvName
      this.form.cinvstd = row.cInvStd
      this.form.ddate = row.dDate
      this.form.socode = row.socode
      this.form.isosid = row.iSOsID
      this.form.csoinvname = row.csoinvname
      this.form.csocode = row.cSOCode
    },
    toNext() {
      getNext(this.$route.query.id).then(res => {
        this.$router.push({ query: { id: res.data.data }})
        if (this.$route.query.id) {
          this.getInCome(this.$route.query.id)
        }
      })
    },
    toLast() {
      getLast(this.$route.query.id).then(res => {
        this.$router.push({ query: { id: res.data.data }})
        if (this.$route.query.id) {
          this.getInCome(this.$route.query.id)
        }
      })
    },
    copyBill() {
      this.form.id = null
      this.form.images = null
      this.form.cinvcode = null
      this.form.mdepcode = null
      this.form.mocode = null
      this.form.moid = null
      this.form.modid = null
      this.form.qty = null
      this.form.qcyqty = null
      this.form.ccomunitname = null
      this.form.cdepname = null
      this.form.define33 = null
      this.form.cinvname = null
      this.form.cinvstd = null
      this.form.ddate = null
      this.form.socode = null
      this.form.isosid = null
      this.form.csoinvname = null
      this.form.csocode = null
      this.$message.success('复制成功!')
    },
    changeAqla() {
      if (!this.form.level) {
        this.$message({
          showClose: true,
          message: '请检测质检等级',
          type: 'warning'
        })
        return
      }
      if (!this.form.qty) {
        this.$message({
          showClose: true,
          message: '请先选择单据',
          type: 'warning'
        })
        return
      }
      if (this.form.aqla === 0) {
        this.form.aca = 0
        this.form.rea = 0
      } else {
        const data = { level: this.form.level, qty: this.form.qty, grade: this.form.aqla }
        get(data).then(res => {
          this.form.aca = res.data.data.ac
          this.form.rea = res.data.data.re
          this.form = JSON.parse(JSON.stringify(this.form))
        })
      }
    },
    changeAqlb() {
      if (!this.form.level) {
        this.$message({
          showClose: true,
          message: '请检测质检等级',
          type: 'warning'
        })
        return
      }
      if (!this.form.qty) {
        this.$message({
          showClose: true,
          message: '请先选择单据',
          type: 'warning'
        })
        return
      }
      if (this.form.aqlb === 0) {
        this.form.acb = 0
        this.form.reb = 0
      } else {
        const data = { level: this.form.level, qty: this.form.qty, grade: this.form.aqlb }
        get(data).then(res => {
          this.form.acb = res.data.data.ac
          this.form.reb = res.data.data.re
          this.form = JSON.parse(JSON.stringify(this.form))
        })
      }
    },
    changeAqlc() {
      if (!this.form.level) {
        this.$message({
          showClose: true,
          message: '请检测质检等级',
          type: 'warning'
        })
        return
      }
      if (!this.form.qty) {
        this.$message({
          showClose: true,
          message: '请先选择单据',
          type: 'warning'
        })
        return
      }
      if (this.form.aqlc === 0) {
        this.form.acc = 0
        this.form.rec = 0
      } else {
        const data = { level: this.form.level, qty: this.form.qty, grade: this.form.aqlc }
        get(data).then(res => {
          this.form.acc = res.data.data.ac
          this.form.rec = res.data.data.re
          this.form = JSON.parse(JSON.stringify(this.form))
        })
      }
    },
    changeDemo() {
      if (this.form.level && this.form.qcyqty) {
        findDemoByLevelAndQty({ level: this.form.level, qty: this.form.qcyqty }).then(res => {
          if (res.code === 200) {
            this.form.checkqty = res.data.data.ISAMPLEQTY
            this.$forceUpdate()
          }
        })
      }
    },
    // 删除操作
    handlefinish(index, row) {
      // 二次确认删除
      this.$confirm('确定要免检吗？', '提示', {
        type: 'warning'
      }).then(() => {
        console.log(row)
        finish(row.MoDId).then(res => {
          this.$message.success('免检成功')
          this.getData()
        })
      })
        .catch(() => {
        })
    },
    changeLevel() {
      if (this.form.aqla) {
        this.changeAqla()
      }
      if (this.form.aqlb) {
        this.changeAqlb()
      }
      if (this.form.aqlc) {
        this.changeAqlc()
      }
      this.changeDemo()
    },
    handleRemove(file, fileList) {
      const images = []
      for (const image of fileList) {
        if (image.response) {
          images.push({ imgUrl: image.response.data.data })
        } else {
          images.push({ imgUrl: image.url.replace(this.fileURL, '') })
        }
      }
      this.form.images = images
    },
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url
      this.dialogVisible = true
    },
    handleExceed() {
      this.$message({
        showClose: true,
        message: '超出限定图片上传个数',
        type: 'error'
      })
    },
    handleUploadSuccess(res, file, fileList) {
      const images = []
      for (const image of fileList) {
        if (image.response) {
          images.push({ imgUrl: image.response.data.data })
        } else {
          images.push({ imgUrl: image.url.replace(this.fileURL, '') })
        }
      }
      this.form.images = images
    }
  }
}
</script>

<style scoped="css">
  .cbody{
    background-color: #fcfcfc;
  }
  select{
    -webkit-appearance:none;
    -moz-appearance:none;
    appearance:none;
  }
  .content{
    margin: 5px auto;
    width: 900px;
    padding: 20px;
    font-size: 14px;
    font-weight: 400;
    background-color: #f7f7f7;
    text-align: center;
  }
  .topth{
    width: 100px;
  }
  .condiv{
    text-align: left;
    border-width: thin;
    border-color: #c7c7c7;
    border-style: solid;
  }
  .table{
    border-collapse: collapse;
    border-color: #c7c7c7;
  }
  .lditem{
    margin: 15px 0;
  }
  .wditem{
    margin: 0 15px;
  }
  .uspan{
    margin: 0 5px;
  }
  .mditem{
    margin: 0 8px;
  }
  .minp{
    width: 50px;
  }
  td{
    border-style: solid;
    border-width: thin;
    border-color: #c7c7c7;
  }
  .handle-input {
    margin: 10px;
    width: 300px;
    display: inline-block;
  }
  .table {
    width: 100%;
  }
  .mincell{
    width: 20px;
  }
  col2{
    colspan:2
  }
  .cselect{
    height: 20px;
    width: 100%;
    text-align: center;
    border-width: 0;
    background-color: #ffffff;
    font-weight: bold;
  }
  .intable{
    font-size: 8px;
    border-width: 0px;
  }
  th{
    border-style: solid;
    border-width: thin;
    font-weight: 400;
    border-color: #c7c7c7;
  }
  .cnumber{
    width: 90px;
  }
  .ditem{
    padding: 20px;
    display: flex;
    justify-content: space-between;
  }
  .red {
    color: #ff0000;
  }
  .hand-btn {
    margin: 5px;
  }
  .gaoya{
    padding-left: 10px;
  }
</style>
